#
# Soul Calculator Example
#

require 'soul/core'

class CalcGrammar < Soul::Grammar

	def initialize
		
		expression = term >> !( 
										('+' >> term)[&do_sum]
									| ('-' >> term)[&do_sub]
								)

		term = factor >> !(
							('*' >> factor)[&do_mul]
							('/' >> factor)[&do_div]
					 )

		factor = 		(+digit)[&do_int]
							| ('(' >> expression >> ')')
							| ('-' >> factor)[&do_neg]
							| ('+' >> factor)

	end

	def start
		self.expression
	end

end

puts "Soul::Calculator Example"

calc = CalcGrammar.new

calc.parse('10 + ( 20 * 2 + 2) / -10')

